package com.sky.controller;

import cn.hutool.core.bean.BeanUtil;
import com.sky.domain.PmsSkuInfo;
import com.sky.service.PmsSkuInfoService;
import com.sky.to.PmsSkuInfoTo;
import com.sky.utils.PageUtils;
import com.sky.utils.R;
import com.sky.vo.param.PmsSkuInfoVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/sku")
public class PmsSkuInfoController {

    @Resource
    private PmsSkuInfoService pmsSkuInfoService;

    @GetMapping("/page")
    public R page(PmsSkuInfoVO vo){
        PageUtils page = pmsSkuInfoService.pageQuery(vo);
        return R.ok(page);
    }

    @GetMapping("/getSkuInfoById")
    public R<PmsSkuInfoTo> getSkuInfoById(@RequestParam("id") Long id){
        PmsSkuInfoTo pmsSkuInfoTo = new PmsSkuInfoTo();
        PmsSkuInfo skuInfo = pmsSkuInfoService.getById(id);
        BeanUtil.copyProperties(skuInfo,pmsSkuInfoTo);
        return R.ok(pmsSkuInfoTo);
    }

    @PostMapping("/getSkuPriceByIds")
    public R<Map<Long, BigDecimal>> getSkuPriceByIds(@RequestBody Set<Long> skuIds){
        Map<Long, BigDecimal> map = pmsSkuInfoService.getSkuPriceByIds(skuIds);
        return R.ok(map);
    }
}
